/**
 * 试管
 */
Testtube = Widget.extend({
	ctor:function(parent){
		this._super();
		parent.addChild(this,29);
		this.setTag(TAG_TESTTUBE);
		this.init();
	},
	init : function(){
		this.setVisible(false);
		this.setCascadeOpacityEnabled(true);

		this.testtube=new Button(this,10,TAG_TESTTUBE1,"#run/testTube.png",this.callback,this);
		this.testtube.setScale(1.5);
		
		this.lid=new Button(this,10,TAG_LID,"#run/plug.png",this.callback,this);
		this.lid.setPosition(cc.p(80, -80));
		this.lid.setScale(0.6);
		
		this.testtube1=new Button(this,10,TAG_TESTTUBE2,"#run/testTube1.png",this.callback,this);
		this.testtube1.setScale(1.5);
		this.testtube1.setVisible(false);
		
		this.film=new Button(this.testtube,10,TAG_LINE,"#run/film.png",this.callback,this);
		this.film.setPosition(this.testtube.width*0.5,0);
		this.film.setVisible(false);
		this.film.setScale(0.1);
		
		this.fog=new Button(this.testtube1,10,TAG_FOG,"#run/fog.png",this.callback,this);
		this.fog.setPosition(this.testtube1.width*0.5,this.testtube1.height*0.7);
		this.fog.setScale(0.5,0.8);
		this.fog.setOpacity(0);
		
		this
		
	},
	lidMove:function(){
		var ber=cc.bezierBy(1, [cc.p(-5,100),cc.p(-80,-180),cc.p(-120, -450)]);
		var rotate=cc.rotateBy(0.2, 180);
		this.lid.runAction(cc.spawn(ber,cc.sequence(rotate,cc.delayTime(0.8))));
	},
	fadeinFog:function(){
		this.fog.runAction(cc.sequence(cc.fadeIn(5)));
	},
	addBubble:function(t){
		var bubble=new cc.Sprite("#run/bubble1.png");
		bubble.setScale(0.5);
		this.testtube1.addChild(bubble);
		bubble.setPosition(cc.p(this.testtube1.width*this.randX(),10));
		bubble.runAction(cc.sequence(cc.spawn(cc.moveBy(t,cc.p(0,45)),cc.scaleBy(t,2)),cc.callFunc(function() {
			bubble.removeFromParent(true);
			if(t>0.3){
				t=t-0.05;
			}else{
				t=0.25;
			}
			this.addBubble(t);
		}, this)));
	},
	randX:function(){
		var x=[0.45,0.455,0.46,0.465,0.47,0.475,0.48,0.485,0.49,0.495,0.50,0.505,0.51,0.515,0.52,0.525,0.53,0.535,0.54,0.545,0.55];
		var X=x[Math.floor(Math.random()*20)];
		return X;
	},
	putTesttube:function(){
		var move=cc.moveBy(1,cc.p(0, 50));
		var rotate=cc.rotateBy(1,-10);
		this.testtube.runAction(cc.spawn(move,rotate));
	},
	upLine:function(){
		var scale=cc.scaleBy(1,4.5);
		var move=cc.moveBy(1,cc.p(0, 60));
		this.film.runAction(cc.sequence(cc.callFunc(function() {
			this.film.setVisible(true);
		},this),cc.spawn(scale,move)));
	},
	putTesttube1:function(){
		var move=cc.moveBy(1,cc.p(0, 50));
		var rotate=cc.rotateBy(1,-10);
		this.testtube.runAction(cc.spawn(move.reverse(),rotate.reverse()));
	},
	callback:function(p){
		var func=cc.callFunc(function() {
			gg.flow.next();
		}, this);
		switch (p.getTag()) {
		case TAG_LID:
			var ber =cc.bezierBy(1, [cc.p(-5,200),cc.p(-80,300),cc.p(-80,230)]);
			p.runAction(cc.sequence(cc.spawn(ber,cc.sequence(cc.delayTime(0.8),cc.callFunc(function() {
				this.testtube1.setVisible(true);
				this.testtube.setVisible(false);
				this.film.removeFromParent(true);
				this.testtube1.addChild(this.film);
				this.film.setPosition(cc.p(this.testtube1.width*0.5,60));
			},this ))),func));
			break;
		case TAG_TESTTUBE2:
			var ber =cc.bezierBy(1, [cc.p(10,80),cc.p(150, 100),cc.p(260,235)]);
			this.runAction(cc.sequence(ber,cc.callFunc(function() {
				ll.run.lamp.setVisible(true);
			},this),func));
			break;
		default:
			break;
		}
	}
});
